<span page-title>{{ 'Apply Errata' | translate }}</span>

<section class="col-md-4" ng-hide="selectedContentHosts">
  <p bst-alert="warning">
    <span translate>You must select at least one Content Host in order to apply Errata.</span>
  </p>
</section>

<section class="col-md-4" ng-hide="errataIds">
  <p bst-alert="warning">
    <span translate>You must select at least one Errata to apply.</span>
  </p>
</section>

<section class="details details-full" ng-show="selectedContentHosts && errataIds">
  <h3 ng-show="errata" translate>Apply {{ errata.errata_id }}</h3>

  <form id="errataActionForm" method="post" action="/katello/remote_execution">
    <input type="hidden" name="remote_action" value="errata_install"/>
    <input type="hidden" name="name" ng-value="errataActionFormValues.errata"/>
    <input type="hidden" name="host_ids" ng-value="errataActionFormValues.hostIds"/>
    <input type="hidden" name="customize" ng-value="errataActionFormValues.customize"/>
    <input type="hidden" name="authenticity_token" ng-value="errataActionFormValues.authenticityToken"/>
    <input type="hidden" name="install_all" ng-value="table.allResultsSelected" />
  </form>

  <section ng-hide="updates.length > 0">
    <div ng-show="errata">
      <p translate ng-show="contentHostIds.length === 0">
        Apply {{ errata.errata_id }} to all Content Host(s)?
      </p>
      <p translate ng-hide="contentHostIds.length === 0">
        Apply {{ errata.errata_id }} to {{ contentHostIds.length  }} Content Host(s)?
      </p>
    </div>

    <div ng-hide="errata">
      <p translate ng-show="contentHostIds.length === 0">
        Apply {{ errataIds.length }} Errata to all Content Host(s)?
      </p>
      <p translate ng-hide="contentHostIds.length === 0">
        Apply {{ errataIds.length }} Errata to {{ contentHostIds.length }} Content Host(s)?
      </p>
    </div>
  </section>

  <section ng-show="updates.length > 0">
    <p translate>
      One or more of the selected Errata are not Installable via your published Content View versions running on the selected hosts.  The new Content View Versions (specified below)
      will be created which will make this Errata Installable in the host's Environment.  This new version will replace the current version in your host's Lifecycle
      Environment.  To install these errata immediately on hosts after publishing check the box below.
    </p>

    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th translate>Content View</th>
          <th translate>Version</th>
          <th translate>Environment</th>
          <th translate>Host Count</th>
        </tr>
      </thead>

      <tbody>
        <tr ng-repeat="update in updates">
          <td>
            <div>
              <span ng-show="update.components.length > 0">
                <i class="fa fa-chevron-down" ng-show="update.componentsVisible && update.components" ng-click="toggleComponents(update)"></i>
                <i class="fa fa-chevron-right" ng-hide="update.componentsVisible && update.components" ng-click="toggleComponents(update)"></i>
              </span>
              <a ui-sref="content-view.version.details({versionId: update.content_view_version.id, contentViewId: update.content_view_version.content_view.id})">{{ update.content_view_version.content_view.name }}</a> <span ng-show="{{update.components}}">*</span>
            </div>
            <div ng-show="update.componentsVisible">
              <span translate>
                Components:
              </span>
              <ul>
                <li ng-repeat="component in update.components" class="row">
                  <a class="col-sm-offset-1" ui-sref="content-view.version.details({versionId: component.id, contentViewId: component.content_view_id">{{ component.name }}</a>
                </li>
              </ul>
            </div>
          </td>
          <td>
            <div>
              {{ update.next_version }}
            </div>
            <div ng-show="update.componentsVisible">
              &nbsp;
              <ul>
                <li ng-repeat="component in update.components">{{ component.next_version }}</li>
              </ul>
            </div>
          </td>
          <td>
            <span ng-repeat="environment in update.environments">
              <a ng-href="/lifecycle_environments/{{ environment.id }}/details">
                {{ environment.name }}
              </a>
              <span ng-show="!$last">, </span>
            </span>
          </td>
          <td>
            {{ update.content_host_count }}
          </td>
        </tr>
      </tbody>
    </table>
  </section>

  <form name="errataConfirm" role="form" ng-submit="confirmApply()">
    <div ng-show="updates && hasComposites(updates)">
      <span translate>
        * These marked Content View Versions are from Composite Content Views.  Their components needing updating are listed underneath.
      </span>
    </div>

    <div class="checkbox" ng-show="updates.length > 0">
      <label>
        <input name="applyErrata" ng-model="applyErrata" type="checkbox"/>
        <span translate>Apply Errata to Content Hosts immediately after publishing.</span>
      </label>
    </div>

    <button type="button" class="btn btn-default" ng-click="transitionBack()" translate>Cancel</button>
    <button type="submit" class="btn btn-primary"
            ng-disabled="applyingErrata || incrementalUpdates.length > 0">
      <i class="fa fa-spinner fa-spin" ng-show="applyingErrata"></i>
      <span ng-show="applyingErrata" translate>Applying</span>
      <span ng-hide="applyingErrata" translate>Confirm</span>
    </button>
  </form>
</section>

